<?php
namespace app\common\model;

/**
 * 定义设备类型
 */
class DeviceType
{
    const DEVICE_LIST = [
        [
            'key'   => 'pc',
            'title' => 'PC网页',
        ],
        [
            'key'   => 'android',
            'title' => '安卓',
        ],
        [
            'key'   => 'ios',
            'title' => 'IOS',
        ],
        [
            'key'   => 'h5',
            'title' => 'H5网页',
        ],
        [
            'key'   => 'miniprogram',
            'title' => '小程序',
        ],
    ];

    /**
     * 根据设备标识获取设备名称
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-08-04
     * @param    string                         $key [description]
     * @return   [type]                              [description]
     */
    public static function getDeviceTitleByKey(string $key, string $default = '未知')
    {
        $data = array_column(DeviceType::DEVICE_LIST, 'title', 'key');

        return $data[$key] ?? $default;
    }

    /**
     * 获取所有设备
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-08-04
     * @return   [type]                         [description]
     */
    public static function getDeviceList()
    {
        return array_column(DeviceType::DEVICE_LIST, 'title', 'key');
    }
}
